package com.ct.gd.passport.domain;

import java.util.HashMap;

import org.ksoap2.serialization.SoapObject;

import com.ct.gd.passport.common.connect.CtServer;
import com.ct.gd.passport.common.constants.Config;
import com.ct.gd.passport.common.constants.Protocol;
import com.ct.gd.passport.common.webservice.WebServiceUtil;
import com.ct.gd.passport.util.TelephonyState;
import com.fuckhtc.gson.Gson;
import com.up91.common.android.connect.Params;
import com.up91.common.android.helper.L;

public class PassportReservation {

	int place;
	String beginDate;
	String endDate;
	String person;
	String phone;
	int bizType;
	int district;
	String date;

	public PassportReservation(int place, String date, String beginDate, String endDate, String person, String phone, int bizType, int district) {
		this.place = place;
		this.beginDate = beginDate;
		this.endDate = endDate;
		this.person = person;
		this.phone = phone;
		this.bizType = bizType;
		this.district = district;
		this.date = date;
	}

	/**
	 * 提交预约表单
	 * <p>
	 * <b>返回值的定义如下：</b>
	 * <p>
	 * －1：预约失败； <br>
	 * 2：有参数为空值； <br>
	 * 3：出入境局ID或业务类型ID数值有误； <br>
	 * 4：预约日期值有误<br>
	 * 若返回值长度大于或等于12位是为工单ID，表示预约成功。
	 * <p>
	 * 
	 * @return
	 */
	public String submit() {
		//		Params params = new Params();
		//		params.put(Protocol.Fields.PLACE, place);
		//		params.put(Protocol.Fields.BEGIN_DATE, beginDate);
		//		params.put(Protocol.Fields.END_DATE, endDate);
		//		params.put(Protocol.Fields.PERSON, person);
		//		params.put(Protocol.Fields.PHONE, phone);
		//		params.put(Protocol.Fields.BIZ_TYPE, bizType);
		//		params.put(Protocol.Fields.DISTRICT, district);
		//		params.put(Protocol.Fields.IMEI, TelephonyState.getInstance().getIMEI());
		//		params.put(Protocol.Fields.USER_PHONE, TelephonyState.getInstance().getPhoneNumber());
		//		String json = CtServer.getServer().doGet(Protocol.Commands.REST_RESERVATIION_SUBMIT, params);
		//		return new Gson().fromJson(json, boolean.class);

		HashMap<String, Object> params = new HashMap<String, Object>();
		SoapObject sob = new SoapObject("", "cbInfo");
		sob.addProperty("barea", place);
		sob.addProperty("bdate", date);
		sob.addProperty("bman", person);
		sob.addProperty("btel", phone);
		sob.addProperty("hkarea", district);
		sob.addProperty("bztype", bizType);
		params.put("cbInfo", sob);
		
		L.i("params", params);
		Object obj = WebServiceUtil
				.callWebService(Config.WEBSERVICE_NAME_SPACE, Config.WEBSERVICE_WSDL, Protocol.Commands.WS_METHOD_BOOK_CRJ, params);
		L.i("submit result:", obj);
		String result = obj.toString();
		return result;// FIX: obj!=null && ...
	}
}
